<!--
 * @Author: yuanweijiang
 * @Date: 2025-02-11 15:19:41
 * @LastEditors: yuanweijiang
-->
<template>
	<el-dialog title="新增接口" width="800" v-model="visible" :close-on-click-modal="false" :destroy-on-close="true" draggable>
		<DataSourceConfigEdit @submitForm="updateDataSourceConfig" :initialDataSourceConfig="dataSourceConfig" />
	</el-dialog>
</template>

<script setup lang="ts">
import DataSourceConfigEdit from './components/DataSourceConfigEdit.vue';
import request from '/@/utils/request111';
import { ElMessage } from 'element-plus';
const visible = ref(false);
const emit = defineEmits(['refresh']);

const dataSourceConfig = ref({});
function getDataSourceConfig(id) {
	let url = '/api/sys/data-source-configs/' + id;
	request(url, { method: 'GET' }).then((response) => {
		if (response.ok) {
			response.json().then((data) => {
				dataSourceConfig.value = data;
			});
		}
	});
}
function updateDataSourceConfig() {
	let config = { method: 'PUT', body: dataSourceConfig.value };
	request('/api/sys/data-source-configs', config).then((response) => {
		if (response.ok) {
			ElMessage.success('更新成功！');
			visible.value = false;
			emit('refresh');
		}
	});
}

function openDialog(id) {
	visible.value = true;
	getDataSourceConfig(id);
}
defineExpose({
	openDialog,
});
</script>

<style scoped></style>
